import { _decorator, Collider, Component, game, Node, PhysicsGroup, RigidBody, Vec3, view } from 'cc';
import { GameUnit } from './GameUnit';
import { GameWorld } from '../GameWorld';
const { ccclass, property } = _decorator;

@ccclass('Edible')
export class Edible extends GameUnit {

    private _IsInViewTiming = 0;
    private _collider : Collider = null;


    protected onLoad(): void {
        this._collider = this.getComponent(Collider);
        this._collider.isTrigger = false;
    }

    start() {

    }

    update(deltaTime: number) {
        if (this._IsInViewTiming >= 0.1) {
            this._IsInViewTiming = 0;
            if(this.IsInView()) {
                if(this.node.scale.x > GameWorld.inst.Slime.node.scale.x) {
                    this._collider.isTrigger = false;
                } else {
                    this._collider.isTrigger = true;
                }
            }
        } else {
            this._IsInViewTiming += deltaTime;
        }
    }
}


